#ifndef _STDDISKOBJECT_H_
#define _STDDISKOBJECT_H_

#define EF_ONLY_FILENAMES	0
#define EF_RELATIVE_NAMES	0
#define EF_FULLY_QUALIFIED	1

#ifdef WIN32
#include <windows.h>
#endif

#include <tchar.h>

#pragma warning(push)

#include <yvals.h>

#pragma warning(disable: 4018)
#pragma warning(disable: 4100)
#pragma warning(disable: 4245)
#pragma warning(disable: 4663)
#pragma warning(disable: 4702)
#pragma warning(disable: 4710)
#pragma warning(disable: 4786)
#pragma warning(disable: 4146)
#pragma warning(disable: 4244)
#pragma warning(disable: 4511)
#pragma warning(disable: 4512)
#pragma warning(disable: 4663)
#pragma warning(disable: 4710)

#include <vector>
#include <string>

#pragma warning(pop)

#pragma warning(disable:4786)

using namespace std;
#ifdef _UNICODE
#define tstring wstring
#else
#define tstring string
#endif

#define _IO_SUCCESS 0
#define _IO_FAILURE	-1

#ifdef WIN32
#define TriggerStdDiskObject( a )	{ if( m_feedbackWindow ) ::SetWindowText( m_feedbackWindow, a ); }
#else
#define TriggerStdDiskObject( a )
#endif

class CStdDiskObject 
{
public:
	// ctor(s)
	CStdDiskObject();

#ifdef WIN32
	CStdDiskObject( HWND feedbackWindow );
#endif

	// dtor
	~CStdDiskObject();

	// - - -
	// Operations

	// Files

	bool FileExists( const tstring& file );
	bool FileInformation( const tstring& file, struct _stat &file_info );
	bool CreateFile( const tstring& file );
	bool CopyFile( const tstring& sourceFile, const tstring& destDirectory );
	bool CopyFile( const tstring& sourceFile, const tstring& destDirectory, const tstring& destFile );
	bool RemoveFile( const tstring& sourceFile );
	bool RenameFile( const tstring& sourceFile, const tstring& destFile );
	bool MoveFile( const tstring& sourceFile, const tstring& destFile );

	bool CopyFiles( const tstring& sourceDirectory, const tstring& destDirectory );
	bool CopyFiles( vector< tstring >& files, const tstring& destDirectory );

	// Directories

	bool DirectoryExists( const tstring& file );

	bool CreateDirectory( const tstring& directory );
	bool CopyDirectory( const tstring& sourceDirectory, const tstring& destDirectory );
	bool EmptyDirectory( const tstring& directory );
	bool RemoveDirectory( const tstring& directory );

	bool CopyDirectories( const tstring& sourceDirectory, const tstring& destDirectory );
	bool EmptyDirectories( const tstring& directory );
	bool RemoveDirectories( const tstring& directory );

	bool EnumFilesInDirectoryWithFilter( const tstring& filter, const tstring& sourceDirectory, vector< tstring >& files, int mode = EF_ONLY_FILENAMES );
	bool EnumAllDirectories( const tstring& sourceDirectory, vector< tstring >& directories, int mode = EF_FULLY_QUALIFIED );
	bool EnumDirectories( const tstring& sourceDirectory, vector< tstring >& directories, int mode = EF_ONLY_FILENAMES );
	bool EnumFilesInDirectory( const tstring& sourceDirectory, vector< tstring >& files, int mode = EF_ONLY_FILENAMES );
	bool EnumAllFiles( const tstring& sourceDirectory, vector< tstring >& files, int mode = EF_FULLY_QUALIFIED );
	bool EnumAllFilesWithFilter( const tstring& filter, const tstring& sourceDirectory, vector< tstring >& files, int mode = EF_FULLY_QUALIFIED );

	bool RenameDirectory( const tstring& oldDirectory, const tstring& newName );
	bool MoveDirectory( const tstring& oldDirectory, const tstring& newDirectory );

	// Error handling
	virtual tstring GetErrorMessage();	

protected:
	virtual void SetSystemErrorMessage( int error, const tstring& elements = _T( "" ) );
	virtual void SetInternalErrorMessage();

private:
	// Error handling
	tstring m_errorMessage;

	void	ClearError();
	bool	EnumAllDirs( const tstring& sourceDirectory, vector< tstring >& directories );
	bool	EnumAllFilesWF( const tstring& filter,const tstring& sourceDirectory, vector< tstring >& files );

	// Helpers
#ifdef WIN32
	HWND	m_feedbackWindow;
#endif

	bool	QualifyPath( tstring& str );
	bool	QualifyFile( tstring& str );
	tstring GetFileName( const tstring& str );
	tstring GetDirectoryName( const tstring& str );
	bool	TestPart( const tstring& str );

};

#endif // _STDDISKOBJECT_H_
